import React, { Component } from "react";
import Son from "./component/son"
console.log(1)
export default class Father extends Component {
    constructor(props) {
        console.log("father-constructor")
        super(props)
        this.state = {
            num: 0,
            flag: true
        }
    }
    componentWillMount() {
        console.log("father-componentWillMount")
    }
    edit = () => {
        this.setState({
            num: 0
        })
    }
    edita = () => {
        a = 20
        console.log(a)
        // 修改普通数据强制刷新
        this.forceUpdate()
    }
    chanage = () => {
        console.log(1)
        this.setState({
            flag: !this.state.flag
        })
    }
    render() {
        console.log("father-render")
        console.log(this.state.flag)
        return (
            <div>
                <h1>father组件</h1>
                <button onClick={this.edit}>修改父组件state.num</button>
                <button onClick={this.edita}>修改a</button>
                <button onClick={this.chanage}>切换</button>
                <hr></hr>
                {this.state.flag && <Son num={this.state.num}></Son>}
                <hr></hr>
            </div>
        )
    }
    componentDidMount() {
        console.log("father-compoentDidMount")
    }
}
let a = 1
console.log(2)